#pragma once
#include <iostream>
#include <signal.h>

#include "../comm/httplib.h"
#include "oj_control.hpp"
using namespace httplib; // 使用httplib命名空间，简化HTTP相关代码的编写
using namespace ns_control;

static Control *ctrl_ptr = nullptr;

void Recovery(int signo)
{
    ctrl_ptr->RecoverMachine();
}

int main()
{

    Server svr;
    // 获取所有的题目列表
    svr.Get("/all_questions", [](const Request &req, Response &resp)
            { resp.set_content("这是所有题目的列表", "text/plain;charset=utf-8"); });

    // 根据题目编号获取题目详情
    svr.Get(R"(/question/(\d+))", [](const Request &req, Response &resp)
            { std::string number = req.matches[1];
        resp.set_content("这是指定的一道题:" + number, "text/plain;charset=utf-8"); });

    // 用户提交代码，使用判题的功能
    svr.Post(R"(/judge/(\d+))", [](const Request &req, Response &resp)
             {
        std::string number=req.matches[1];
        resp.set_content("这是题目的判题:"+number,"text/plain;charset=utf-8"); });

    svr.set_base_dir("./wwwroot");
    svr.listen("0.0.0.0", 8080);
    return 0;
}